<?php
if( !isset($AppUI) || !isset($_SESSION['user'])) {
	redirect(HOST_BACKEND);
}

$intAction 		= $this->input->post('paction', 0);
$arrUserId 		= $this->input->post('puserid', null);test($arrUserId);
$strError		= '';
$strMsg			= '';

if($intAction && $arrUserId) {
	$this->load->model('user_model', 'user');	
	switch ($intAction) {
		case 1: // active
			if(isset($_SESSION['user']) && ($_SESSION['user']&1<<5) != 0) {							
				foreach($arrUserId as $row) {
					$intError  = $this->user->updateStatus($AppUI->id,$row,1,1<<5);
				}
				$strMsg		= $arrMessage['user_update'];
			}
			else {
				$strError	= $arrError['noperm_user_update'];
			}
			break;
		case 2: // delete
			if(isset($_SESSION['user']) && ($_SESSION['user']&1<<3) != 0) {				
				foreach($arrUserId as $row) {
					$this->user->updateStatus($AppUI->id,$row,4,8);
				}
				$strMsg		= $arrMessage['user_delete'];
			}
			else {
				$strError	= $arrError['noperm_user_delete'];
			}
			break;
		case 3://suspend
		
			if(isset($_SESSION['user']) && ($_SESSION['user']&1<<4) != 0) {	
				foreach($arrUserId as $row) {
					$intError  = $this->user->updateStatus($AppUI->id,$row,2,1<<4);
				}
				$strMsg		= $arrMessage['user_update'];
			}
			else {
				$strError	= $arrError['noperm_user_update'];
			}
			break;
		case 4://inactive
	
		if(isset($_SESSION['user']) && ($_SESSION['user']&1<<5) != 0) {	
			foreach($arrUserId as $row) {
				$intError  = $this->user->updateStatus($AppUI->id,$row,0,1<<5);
			}
			$strMsg		= $arrMessage['user_update'];
		}
		else {
			$strError	= $arrError['noperm_user_update'];
		}
		break;
		
	}
} else {
	$strError	= $arrError['nodata_act'];
}
if($strError == '') {
	CI_Function::setMsg($strMsg);
} else {
	CI_Function::setError($strError);	
}
redirect(HOST_BACKEND.'user');

